/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package financialcalendar;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 *
 * @author James
 */
public class FinancialCalendar extends Calendar {
    public double goal;
    public double dailySavingGoal;
    public int goalDate;
    public int goalMonth;
    public int goalYear;
    public GoalType goalType;
    public Date today;
    public double projectedDailySavings;
    public double projectedWeeklySavings;
    public double projectedMonthlySavings;
    public double projectedYearlySavings;
    public boolean isLeapYear = false;
    
    public FinancialCalendar(double g, int gD, int gM, int gY, GoalType gT)
    {
        goal = g;
        goalDate = gD;
        goalMonth = gM;
        goalYear = gY;
        goalType = gT;
    }
    
    //adds an amount to the account in question.
    public double add(User u, double am){
        
        u.currentBalance = u.currentBalance + am;
        u.amountSavedThisMonth += am;
        u.amountSavedThisWeek += am;
        u.amountSavedToday += am;
        return u.currentBalance;
        
    }
    
    //subtracts an amount from the account in question.
    public double subtract(User u, double am){
        
        u.currentBalance = u.currentBalance - am;
        u.amountSavedThisMonth -= am;
        u.amountSavedThisWeek -= am;
        u.amountSavedToday -= am;
        return u.currentBalance;
        
    }
    //Indicates predicted savings for the week. To be done on each Monday.
    //ALPHA VERSION: shows the amount which will be saved per week if you follow the daily savings suggestions
    public double calculateIdealWeeklyProjectedSavings(User u, GoalType gt){            
            projectedWeeklySavings =  7 * projectedDailySavings;
            return projectedWeeklySavings;
    }
    public void calculateIdealProjectedSavings(User u) //This method calculates the suggested savings
    {                                                   //over different time periods by calling the methods listed
        calculateIdealDailyProjectedSavings(u);
        calculateIdealWeeklyProjectedSavings(u, u.myCalendar.goalType);
        calculateIdealMonthlyProjectedSavings(u, u.myCalendar.goalType);
        calculateIdealWeeklyProjectedSavings(u, u.myCalendar.goalType);
    }
    public double calculateIdealDailyProjectedSavings(User u)
    {
        GregorianCalendar c = new GregorianCalendar(goalYear,goalMonth-1,goalDate);
        today = new Date();
        
        Date d1 = c.getTime();
        int days = (int)((d1.getTime() - today.getTime()) / (1000 * 60 * 60 * 24));
        projectedDailySavings = (goal - u.currentBalance) / days;
        if (projectedDailySavings < 0)
            projectedDailySavings = 0;
        return projectedDailySavings;
    }
    public double calculateIdealMonthlyProjectedSavings(User u, GoalType gt){
        
        switch(MONTH){
        
            case JANUARY:
                projectedMonthlySavings = 31 * projectedDailySavings;
                return projectedMonthlySavings;
            case FEBRUARY:
                if(isLeapYear == true){
                projectedMonthlySavings = 29 * projectedDailySavings;
                return projectedMonthlySavings;
                }
                else
                    projectedMonthlySavings = 28 * projectedDailySavings;
                return projectedMonthlySavings;
            case MARCH:
                projectedMonthlySavings = 31 * projectedDailySavings;
                return projectedMonthlySavings;
            case APRIL:
                projectedMonthlySavings = 30 * projectedDailySavings;
                return projectedMonthlySavings;
            case MAY:
                projectedMonthlySavings = 31 * projectedDailySavings;
                return projectedMonthlySavings;
            case JUNE:
                projectedMonthlySavings = 30 * projectedDailySavings;
                return projectedMonthlySavings;
            case JULY:
                projectedMonthlySavings = 31 * projectedDailySavings;
                return projectedMonthlySavings;
            case AUGUST:
                projectedMonthlySavings = 31 * projectedDailySavings;
                return projectedMonthlySavings;
            case SEPTEMBER:
                projectedMonthlySavings = 30 * projectedDailySavings;
                return projectedMonthlySavings;
            case OCTOBER:
                projectedMonthlySavings = 31 * projectedDailySavings;
                return projectedMonthlySavings;
            case NOVEMBER:
                projectedMonthlySavings = 30 * projectedDailySavings;
                return projectedMonthlySavings;
            case DECEMBER:
                projectedMonthlySavings = 31 * projectedDailySavings;
                return projectedMonthlySavings;
        }
        return projectedMonthlySavings;
    }
    
    public double calculateIdealYearlyPredictedSavings(User u, GoalType gt){
        
        if(isLeapYear == true){
            projectedYearlySavings = 366 * projectedDailySavings;
            return projectedYearlySavings;
        }
        else
            projectedYearlySavings = 365 * projectedDailySavings;
            return projectedYearlySavings;
    }
    
    @Override
    protected void computeTime() {
        throw new UnsupportedOperationException("Not supported yet.");
        //if()
    }

    @Override
    protected void computeFields() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void add(int field, int amount) {
        throw new UnsupportedOperationException("Not supported yet.");
        
    }

    @Override
    public void roll(int field, boolean up) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getMinimum(int field) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getMaximum(int field) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getGreatestMinimum(int field) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int getLeastMaximum(int field) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}